
<?php

require('_config-rating.php');

if (isset($_GET["page"])) 
{ 
	$page  = $_GET["page"]; 
} else { 
	$page=1; 
};

/*if (isset($_GET["userid"])) 
{ 
	$userid  = $_GET["userid"]; 
} else { 
	$userid=123456; 
};*/

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
}

$sql = "SELECT COUNT(*) FROM games WHERE gameId IN (SELECT gameId FROM favorites WHERE personId =$userid )";
$rs_result = mysql_query($sql,$con); 
if($rs_result){
	if ($row = mysql_fetch_array($rs_result)){
		
	$total_records = $row[0]; 
	$total_pages = ceil($total_records / $pageInclude); 
	$outputPagination='<div class="navigation">';
	$outputPagination=$outputPagination.'<div align="center" class="navigation"><ol class="wp-paginate"><li><span class="title"></span></li>';

	$startPage=1;
	$pageCount=2;
	if ($pageCount>=$total_pages){
		$startPage=1;
		$loopCount=$total_pages;
	}else if($page+$pageCount<=$total_pages){
		if ($page>1)$startPage=$page-1;
		else $startPage=1;
		$loopCount=$startPage+$pageCount;
	}else if($page+$pageCount>$total_pages){
		$startPage=$total_pages-$pageCount;
		$loopCount=$startPage+$pageCount;
	}
	/*if($page+$pageCount<=$total_pages && $page-1>0){
		$startPage=$page-1;
	}else if($page+$pageCount>$total_pages){
		$startPage=$total_pages-$pageCount;
	}*/

	if(($page-1)>0){
		$outputPagination=$outputPagination.'<li><a class="next" href="myProfile.php?page='.($page-1).'">«</a></li>';
	}
	for ($i=$startPage; $i<=$loopCount; $i++) { 
		if($page==$i){
			$outputPagination=$outputPagination.'<li><span class="page current">'.$i.'</span></li>';
		}else{
			$outputPagination=$outputPagination.'<li><a class="page" title='.$i.' href="myProfile.php?page='.$i.'">'.$i.'</a></li>';
		}
		//echo "<a href='pagination.php?page=".$i."'>".$i."</a> "; 
	};
	if(($page+1)<=$total_pages){
		$outputPagination=$outputPagination.'<li><a class="next" href="myProfile.php?page='.($page+1).'">»</a></li>';
	}

	$outputPagination=$outputPagination.'</ol></div></div>';
	}

	echo $outputPagination;
}
mysql_close();
?>
